#ifndef _DKGL_UTILITY_H_ 
#define _DKGL_UTILITY_H_

#include "dkglPreRequest.h"

namespace DKGL
{

class Vector3;

bool EnableOpenGL(HDC  hDC, HGLRC *hRC);
void DisableOpenGL(HGLRC hRC);

void SetIdentityMatrix(float *m);
void CopyMatrix(float *m_dest, const float *m_source); 
void InvAffineMat(float*);
void InvAffineMat(float* inv_dest, const float* inv_src);

void ToCameraMatrix( float *cam_matrix, const float *matrix);
void MultRotPartOnly(float *dest, const float *source);

inline Real Degree2Radian(double deg) { return deg * DEG2RAD; }
inline Real Radian2Degree(double rad) { return rad * RAD2DEG; }

inline Real InvSqrt(Real val) { return Real(1.0) / sqrt( val ); }

/** Compare 2 reals, using tolerance for inaccuracies.
        */
inline bool RealEqual(Real a, Real b, Real tolerance = std::numeric_limits<Real>::epsilon())
{
	if (fabs(b-a) <= tolerance)
        return true;
    else
        return false;
}

Vector3 CalculateNormal(const Vector3& p1, const Vector3& p2, const Vector3& p3);
bool LineAndTriangleIntersection(const Vector3& linep,const Vector3& d, 
								 const Vector3& tri0, const Vector3& tri1, const Vector3& tri2,Vector3& out);

//using namespace std;
//Converting a WChar string to a Ansi string
std::string WChar2Ansi(LPCWSTR pwszSrc);
std::string ws2s(const std::wstring& inputws);

//Converting a Ansi string to WChar string
std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen);
std::wstring s2ws(const std::string& s);//{ return Ansi2WChar(s.c_str(), static_cast<int>(s.size()));}

}
#endif